#include<iostream>
#include<map>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
map<int, int>mp;
int n, d;
int w[N];
int main()
{
	cin >> n >> d;
	int idx = 0;
	for (int i = 1; i <= n; i++) {
		cin >> w[i];
		if (w[i] == d)idx = i;
	}
	int ans = 0;
	for (int i = idx; i <= n; i++) {
		if (w[i] > d)ans++;
		else if (w[i] < d)ans--;
		mp[ans]++;
	}
	LL res = 0;
	ans = 0;
	for (int i = idx; i >= 1; i--) {
		if (w[i] > d)ans++;
		else if (w[i] < d)ans--;
		res += mp[0 - ans];
	}
	cout << res << endl;
	return 0;
}